import 'dart:ui';
import 'package:sports_new/resources/colours.dart';
import 'package:sports_new/utils/date_time_utils.dart';

enum ChatMessageType{
  comment,
  enter(color: Colours.grey99),
  focus(color: Colours.grey99),
  gift(color: Colours.grey99),
  system(color: Color(0xFFF55F5F)),
  unKnow(color: Colours.grey99);

  final Color color;

  const ChatMessageType({this.color = Colours.text});

  static ChatMessageType getType(int? type){
    switch (type) {
      case 1:
        return ChatMessageType.comment;
      case 2:
        return ChatMessageType.enter;
      case 3:
        return ChatMessageType.focus;
      case 4:
        return ChatMessageType.gift;
      case 99:
        return ChatMessageType.system;
      default:
        return ChatMessageType.unKnow;
    }
  }
}

class LiveChatEntity {
  String? createTime;
  int? id;
  String? message;
  ChatMessageType? type;
  String? userId;
  String? userName;

  LiveChatEntity(
      {this.createTime,
        this.id,
        this.message,
        this.type,
        this.userId,
        this.userName});

  LiveChatEntity.fromJson(Map<String, dynamic> json) {
    if(json['createTime'] is int){
      createTime = DateTime.fromMillisecondsSinceEpoch(json['createTime']).formatedString();
    }else{
      createTime = json['createTime'];
    }
    id = json['id'];
    message = json['message'];
    type = ChatMessageType.getType(json['type']);
    userId = json['userId'];
    userName = json['userName'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['createTime'] = this.createTime;
    data['id'] = this.id;
    data['message'] = this.message;
    data['type'] = this.type;
    data['userId'] = this.userId;
    data['userName'] = this.userName;
    return data;
  }
}